package com.yanq.liancar.activity;
/*
 *  @创建者     liyan
 *  @创建时间   2018/11/6  15:30
 *  @描述       ${TODO}
 */


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.adapter.DrivingTrackAdapter;
import com.yanq.liancar.bean.DrivingTrack;
import com.yanq.liancar.util.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DrivingTrackActivity extends BaseToolbarActivity {
    @BindView(R.id.trajectory_recyclerview)
    RecyclerView mRecyclerview;
    @BindView(R.id.SmartRefreshLayout)
    com.scwang.smartrefresh.layout.SmartRefreshLayout mSmartRefreshLayout;

    private int page = 1;
    private int pages;
    private boolean isClear = true;
    private DrivingTrackAdapter mListAdapter;
    private List<DrivingTrack> mList=new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drivingtrack);
        ButterKnife.bind(this);
        Utils.setStatusBar(this, true, false);
        mTvTitle.setText("行车轨迹");

        initView();
        initOkgo();
    }

    private void initView() {
        initRecyclerview();
        initListener();
    }

    private void initRecyclerview() {

        //        mRecyclerview.setNestedScrollingEnabled(false);
        //        mRecyclerview.setLayoutManager(new LinearLayoutManager(mActivity));
        //        mListAdapter = new DrivingTrackAdapter(R.layout.item_drivingtracklist, mList);
        //        mRecyclerview.setAdapter(adapter);
        //        mListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
        //            @Override
        //            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        //                Bundle bundle = new Bundle();
        //                bundle.putInt("orderId", mList.get(position).getOrderid());
        //                bundle.putInt("orderStatus", mList.get(position).getOrder_status());
        //                readyGo(DrivingTrackActivity.class, bundle);
        //            }
        //        });

    }

    private void initListener() {
        mSmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                page = 1;
                isClear = true;

                initOkgo();
                refreshlayout.finishRefresh();
            }
        });
        mSmartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                page++;
                isClear = false;
                if (pages >= page) {
                    initOkgo();
                }
                refreshLayout.finishLoadMore();
            }

        });
    }

    //列表数据
    private void initOkgo() {
        //        OkGo.<String>post(Config.s + "llc/api/selectUserAllOrders")
        //                .tag(this)
        //                .params("token", UserBean.getbToken(mActivity))
        //                .params("pageNum",page)
        //                .params("pageSize",10)
        //                .params("order_status",auditStatus)
        //                .execute(new StringCallback() {
        //                    @Override
        //                    public void onSuccess(Response<String> response) {
        //                        Gson gson = new Gson();
        //                        TrajectoryListBean bean = gson.fromJson(response.body(), TrajectoryListBean.class);
        //                        if (bean.isIsSuccess()) {
        //                            pages = bean.getData().getPages();
        //                            if (isClear) {
        //                                mList.clear();
        //                            }
        //                            mList.addAll(bean.getData().getList());
        //                            adapter.setNewData(mList);
        //                        } else {
        //                            RxToast.error(bean.getOutputMessage());
        //                        }
        //                    }
        //
        //                    @Override
        //                    public void onError(Response<String> response) {
        //                        super.onError(response);
        //                        RxToast.error("服务器连接错误");
        //                    }
        //                });
    }
}
